package com.breakfast.fun.ui.other.city;

import com.breakfast.fun.data.entity.home.City;
import com.breakfast.fun.util.Api;
import com.breakfast.fun.util.T;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/8/22.
 */
public class CityPresenter extends CityContract.Presenter {
    @Override
    public void getCity() {
        Map<String, String> map = Api.getInstance().getBaseParams();

        map.put("action", "list");

        showLoadingDialog(true);
        rxManager.add(model.getCityModel(map)
                .subscribeOn(Schedulers.computation())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new Subscriber<City>() {
                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        hideLoadingDialog();
                        T.show("获取数据失败");
                    }

                    @Override
                    public void onNext(City city) {
                        if (city.isSuccess()) {
                            view.showCity(city.getData());
                        } else {
                            T.show(city.getMsg());
                        }
                        hideLoadingDialog();
                    }

                }));
    }

    @Override
    public void onStart() {
        getCity();
    }
}
